package com.larissa.quiz;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class HelpActivity extends AppCompatActivity implements View.OnClickListener {
    private static final String TAG="HelpActivity";
    private static final String KEY_ANSWER="answer";
    private static final String KEY_RESULT="result";
    private Button btnShowAnswer;
    private TextView answerTextView;
    private boolean answer;
    private boolean hasClicked=false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_help);

        Log.d(TAG,"onCreate() called");
        getSupportActionBar().setTitle(TAG);
        answer=getIntent().getBooleanExtra(KEY_ANSWER,true);

        answerTextView=findViewById(R.id.tx_answer);
        btnShowAnswer=findViewById(R.id.btn_show_answer);
        btnShowAnswer.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        answerTextView.setText(String.valueOf(answer));
        hasClicked=true;
        setActivityResult();
    }

    private void setActivityResult(){
        Log.d(TAG,"setActivityResult() called");
        Intent intent=new Intent();
        intent.putExtra(KEY_RESULT,hasClicked);
        setResult(RESULT_OK,intent);
    }

    @Override
    public void onStart(){
        super.onStart();
        Log.d(TAG,"onStart() called");
    }

    @Override
    public void onResume(){
        super.onResume();
        Log.d(TAG,"onResume() called");
    }

    @Override
    public void onPause(){
        super.onPause();
        Log.d(TAG,"onPause() called");
    }

    @Override
    public void onStop(){
        super.onStop();
        Log.d(TAG,"onStop() called");
    }

    @Override
    public void onDestroy(){
        super.onDestroy();
        Log.d(TAG,"onDestroy() called");
    }
}